<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function CURLSend($url, $method = 'get', $data = '') {
    $ch = curl_init(); //初始化
    $headers = array('Accept-Charset: utf-8');
    //设置URL和相应的选项
    curl_setopt($ch, CURLOPT_URL, $url); //指定请求的URL
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); //提交方式
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //不验证SSL
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //不验证SSL
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //设置HTTP头字段的数组
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible;MSIE 5.01;Windows NT 5.0)'); //头的字符串

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1); //自动设置header中的Referer:信息

    curl_setopt($ch, CURLOPT_POSTFIELDS, ['jsonstr' => json_encode($data)]);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //是否输出到屏幕上,true不直接输出
    $temp = curl_exec($ch); //执行并获取结果
    curl_close($ch);
    return $temp; //return 返回值json字符串
}


$receiver = [
    ['email'=>'1021840359@qq.com'],
    ['email'=>'2745470458@qq.com'],
    ['email'=>'15656567326@163.com'],
];
$sendname = 'mike';
//$sender = 'admin@yr8m.com';
//$sender = 'admin@bonsai-zoo.com';
$sender = 'admin@yr8m.com';

$subject = 'hello';
$content = 'hello world';
$attachment = '';

$data = [
    'operatorinfo' => [//操作人信息
        'department_id' => 1,
        'uid' => 1,
    ],
    'receiver' => $receiver, //收件人信息
    'emailinfo' => [//邮件信息
        'sender' => $sendname, //发件人昵称
        'from' => $sender, //发件邮箱
        'subject' => $subject, //邮件主题
        'content' => $content, //邮件内容
        'attachment' => $attachment//附件
    ]
];
$url = 'http://58.84.53.170/index.php/api/mail';
$state = CURLSend($url, 'post', $data);
print_r($state);
